package com.northpool.operator.common.test;

import com.northpool.operator.annotation.InputParam;
import com.northpool.operator.annotation.InputParams;
import com.northpool.operator.annotation.OperatorInfo;
import com.northpool.operator.annotation.OutputParam;
import com.northpool.operator.annotation.OutputParams;
import com.northpool.operator.common.algorithm.OperatorTestBuild;
import com.northpool.operator.common.algorithm.TestParamBuilder;
import com.northpool.operator.param.ParamTool;
import com.northpool.operator.type.TypeEnum;
import com.northpool.operator.utils.StpOperatorHelper;

@OperatorInfo(
        ref = "ParamTestOperator",
        name = "参数验证",
        description = "验证参数是否符合预期"
)
@OutputParams({
        @OutputParam(ref = "result", type = TypeEnum.BOOL, name = "验证结果", desc = "验证结果布尔值")
})
public class ParamTestOperator extends StpOperatorHelper {

    @InputParams({
            @InputParam(ref = "str", name = "参数值", desc = "实际的参数值", required = true),
            @InputParam(ref = "except", name = "期望值", desc = "期望的参数值", required = true),
    })
    public ParamTestOperator() {
    }

    public static void main(String[] args) throws Exception {
        OperatorTestBuild.execute(ParamTestOperator.class,
                TestParamBuilder.aBuilder()
                        .param("str", "test")
                        .param("except", "test")
                        .build()
        );
    }

    @Override
    public void execute(ParamTool params) {
        String str = params.getStr("str");
        String except = params.getStr("except");
        if (str.equals(except)) {
            this.result("result", true);
        } else {
            this.result("result", false);
        }
    }
}
